from django.contrib import admin


class BaseProfileInline(admin.StackedInline):
    verbose_name_plural = 'Profile Information'
    verbose_name = 'Profile Type'
    can_delete = False
    max_num = 1


class ProfileInlinesManager:

    inline_classes = {}

    @staticmethod
    def create_inline_class(profile_type, profile_model):

        class ProfileInline(BaseProfileInline):
            __name__ = profile_model.__class__.__name__ + 'Inline'
    	    model = profile_model

        ProfileInlinesManager.inline_classes[profile_type] = ProfileInline

    @staticmethod
    def get_inline_classes():
        if ProfileInlinesManager.inline_classes:
            return ProfileInlinesManager.inline_classes

        from multiprofiles.collector import ProfileCollector

        for (type, model) in ProfileCollector.profiles.items():
            ProfileInlinesManager.create_inline_class(type, model)

        return ProfileInlinesManager.inline_classes